import face_recognition
import cv2
import os
from ament_index_python.packages import get_package_share_directory # 获取功能包share目录绝对路径

def main():
    # 获取图片的路径                       # 函数返回值是绝对路径 
    default_image_path = os.path.join(get_package_share_directory('demo_python_service'), 'resource/default.jpg') 
    print(f"图片的绝对路径是：{default_image_path}")
    
    # 使用OpenCV来加载图片
    image = cv2.imread(default_image_path)
    # 检测人脸
    face_locations = face_recognition.face_locations(image, number_of_times_to_upsample = 1, model = 'hog')
    # 绘制框
    for top, right, bottom, left in face_locations:
        cv2.rectangle(image, (left, top), (right, bottom), (255, 0, 255), 4)
        
    # 结果显示
    cv2.imshow('dog', image)
    cv2.waitKey(0)
